package org.itboys.mobile.controller.mobile.common;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * 作者：jiangxiong
 * 日期：2017年2月8日
 * 联系方式 ：empty90911@126.com
 * 描述：圣代_更新APK_controller。
 */
@RestController
@RequestMapping("/sunday/mobile/apk")
@Api(value = "apk",description = "更新APK")
public class SundayMobileApkController extends BaseController {



        @RequestMapping(value="/upload", method=RequestMethod.POST)
        @ApiOperation(value="上传最新的包文件，苹果版本不需要上传包。")
        public void upload(HttpServletResponse response,
                           @ApiParam(required=false, name="file", value="附件流。【安卓专用】")@RequestParam(value ="file",required=false) MultipartFile file,
                           @ApiParam(required=false, name="log", value="更新日志")@RequestParam(value ="log",required=true) String log,
                           @ApiParam(required=true, name="type", value="1，安卓用户版本，2，安卓管理版，3，苹果用户版，4，苹果管理版")@RequestParam(value ="type",required=true) Integer type,
                            @ApiParam(required = true, name = "token", value = "签名") @RequestParam(value = "token", required = true) String token){

            try {
          /*      AjaxUtils.renderJsonporJson(response, null,
                        ResultPageDOHelper.getMsgResultDO(-2,"没有更新可用。"));*/
              AjaxUtils.renderJsonporJson(response, null,
                        ResultPageDOHelper.getMsgResultDO( CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("/mobile/apk/upload--------"+e);
                AjaxUtils.renderJsonporJson(response, null,
                        ResultPageDOHelper.getMsgCodeResultDO(
                                CommonConstants.FAIL_CODE, CommonConstants.ERROMSG));

            }
        }

        @RequestMapping(value="/getApkInfo", method=RequestMethod.POST)
        @ApiOperation(value="获取最新版本版本信息。0有更新，-2无更新，-1系统错误")
        public void getApkInfo(HttpServletResponse response,
                       @ApiParam(required=true, name="type", value="1，安卓用户版本，2，安卓管理版(暂无)，3，苹果用户版，4，苹果管理版(暂无)")@RequestParam("type") Integer type,
                       @ApiParam(required=true, name="versionCode", value="版本号。")@RequestParam("versionCode") Integer versionCode) {
            try {

                AjaxUtils.renderJsonporJson(response, null,
                        ResultPageDOHelper.getMsgResultDO(-2,"没有更新可用。"));
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("/mobile/apk/getApkInfo--------"+e);
                AjaxUtils.renderJsonporJson(response, null,
                        ResultPageDOHelper.getMsgCodeResultDO(
                                CommonConstants.FAIL_CODE, CommonConstants.ERROMSG));

            }
        }

}
